#include <stdio.h>
#include <stdlib.h>

typedef struct data
{
    int T;
    int H;
} data;

void * my_realloc (data *ptr, size_t size,size_t size_0)
{
    if (size == 0)
    {
        return NULL;
    }
    else if (size >= size_0)
    {
        data *P = (data *)malloc( size * sizeof(data));
        
        for (size_t i = 0; i < size_0; i++)
        {
            P[i].T = ptr[i].T;
            P[i].H = ptr[i].H;
        }
        free(ptr);
        return P;
    }
    else if (size <= size_0)
    {
        data *P = (data *)malloc( size * sizeof(data));
        
        for (size_t i = 0; i < size; i++)
        {
            P[i].T = ptr[i].T;
            P[i].H = ptr[i].H;
        }
        free(ptr);
        return P;
    }
    else if (ptr == NULL)
    {
        data *P = (data *)malloc( size * sizeof(data));
        return P;
    }
    
    
    

}

int main(int argc, char const *argv[])
{
    data *P;
    data *F = (data *)malloc( 10 * sizeof(data));
    if (NULL == F)
    {
        printf("创建失败\n");
        return -1;
    }
    F->T = 10;
    F->H = 30;
    for (size_t i = 0; i < 10; i++)
    {
        printf("H = %d\tT =%d\n",F[i].H ,F[i].T);
    }
    printf("\n");
    P = my_realloc( F , 50 ,10 );
    for (size_t i = 0; i < 50; i++)
    {
        printf("H = %d\tT =%d\n",P[i].H ,P[i].T);
    }
    free(P);
    return 0;
}